package com.sqoq.downloader3.ui

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.lifecycle.lifecycleScope
import com.sqoq.downloader3.MainActivity
import com.sqoq.downloader3.R
import com.sqoq.downloader3.base_ddg.BaseActivity_ddg
import com.sqoq.downloader3.databinding.ActivityLunchDdgBinding
import com.tencent.mmkv.MMKV
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

class LunchActivity_ddg : BaseActivity_ddg<ActivityLunchDdgBinding>() {
    var path: String? = null
    override val layout: Int
        get() = R.layout.activity_lunch_ddg

    override fun initView() {
        path = intent.getStringExtra(Intent.EXTRA_TEXT)
        lifecycleScope.launch(Dispatchers.Default) {
            delay(1000)
            withContext(Dispatchers.Main) {
                if (MMKV.defaultMMKV().decodeBool("firstopen_ddg", true)) {

                    startActivity(FirstLunchActivity_ddg::class.java)
                } else {
                    startActivity(MainActivity::class.java, argument = {
                        it.putExtra("path_ddg", path)
                    })
                }
                finish()
            }
        }
    }
}